package paskal.audio.player;

/**
 * This class implements player events.
 */
public class PlayerEvent {
	public static final int UNKNOWN = -1;
	public static final int OPENING = 0;
	public static final int OPENED = 1;
	public static final int PLAYING = 2;
	public static final int STOPPED = 3;
	public static final int PAUSED = 4;
	public static final int RESUMED = 5;
	public static final int SEEKING = 6;
	public static final int SEEKED = 7;
	public static final int EOM = 8;
	public static final int GAIN = 10;
	public static final int VOLUME = 11;
	public static final int CAHSING = 12;
	public static final int CAHSED = 13;
	private int code = UNKNOWN;
	private double position = 0;
	private double value = -1.0;
	private Object source = null;
	private Object description = null;

	/**
	 * Constructor
	 * 
	 * @param source
	 *            of the event
	 * @param code
	 *            of the envent
	 * @param position
	 *            optional stream position
	 * @param value
	 *            opitional control value
	 * @param desc
	 *            optional description
	 */
	public PlayerEvent(Object source, int code, double position, double value,
			Object desc) {
		this.value = value;
		this.position = position;
		this.source = source;
		this.code = code;
		this.description = desc;
	}

	/**
	 * Return code of the event triggered.
	 * 
	 * @return
	 */
	public int getCode() {
		return code;
	}

	/**
	 * Return position in the stream when event occured.
	 * 
	 * @return
	 */
	public double getPosition() {
		return position;
	}

	/**
	 * Return value related to event triggered.
	 * 
	 * @return
	 */
	public double getValue() {
		return value;
	}

	/**
	 * Return description.
	 * 
	 * @return
	 */
	public Object getDescription() {
		return description;
	}

	public Object getSource() {
		return source;
	}

	public String toString() {
		switch (code) {
		case OPENED:
			return "OPENED:" + position;
		case OPENING:
			return "OPENING:" + position + ":" + description;
		case PLAYING:
			return "PLAYING:" + position;
		case STOPPED:
			return "STOPPED:" + position;
		case PAUSED:
			return "PAUSED:" + position;
		case RESUMED:
			return "RESUMED:" + position;
		case SEEKING:
			return "SEEKING:" + position;
		case SEEKED:
			return "SEEKED:" + position;
		case EOM:
			return "EOM:" + position;
		case GAIN:
			return "GAIN:" + value;
		case VOLUME:
			return "VOLUME:" + value;
		case CAHSING:
			return "CAHSING:" + position;
		case CAHSED:
			return "CAHSED:" + position;
		default:
			return "UNKNOWN:" + position;
		}
	}
}